<?php
/* @var $this CourseController */
/* @var $model Course */
/* @var $form CActiveForm */
/* @var $id course id */
?>

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl('course/viewSubModules', array('id'=>$id)),
	'method'=>'get',
)); ?>
    
<?php
	$course = Course::model()->findByPk($id);
	$criteria = new CDbCriteria;
	
	// change date format for query
	$originalStartDate = $course->start;
	$startDateFormat = date("Y-m-d", strtotime($originalStartDate));
	
	$originalEndDate = $course->end;
	$endDateFormat = date("Y-m-d", strtotime($originalEndDate));
	
	echo('course start: ' . $course->start . ' course end: ' . $course->end);
	echo('<br>');
	echo('<br>');
	
	$criteria->condition='start>=:course_start AND end<=:course_end AND is_module=:is_module';
	$criteria->params=array(':course_start'=>$startDateFormat, ':course_end'=>$endDateFormat, ':is_module'=>1);
	
	$modules = Course::model()->findAll($criteria); 
	
	echo('found modules: ' . count($modules));
	echo('<br>');
	echo('<br>');
	
	foreach($modules as $m) {
		echo($m->course_nr . '<br>');
	}

	echo('<br>');


    // Date range search inputs
    $attribute = 'start';
    for ($i = 0; $i <= 1; $i++)
    {
        echo ($i == 0 ? Yii::t('main', 'Von:') : Yii::t('main', 'Bis:'));
        $this->widget('ext.bootstrap.widgets.TbDatePicker', array(
            'id'=>CHtml::activeId($model, $attribute.'_'.$i),
            'model'=>$model,
            'attribute'=>$attribute."[$i]",
            'options'=>array( 
                        'format' => 'dd.mm.yyyy', 
                    ),
        )); 
    }
?>

<div class="row buttons">
	<?php echo CHtml::submitButton('Search'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- search-form -->

